package com.asura.qqeffect.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

/**
 * Created by Asura on 2016/12/8.
 */

public class DemoScrollView extends ScrollView {
    public DemoScrollView(Context context) {
        super(context);
    }

    public DemoScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DemoScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    int lastY;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        View view = ((ViewGroup) getChildAt(0)).getChildAt(0);
        int[] point = new int[2];
        view.getLocationInWindow(point);

        switch (ev.getAction()) {
            case MotionEvent.ACTION_MOVE:
                Log.i("TAG","ACTION_MOVE");
//                int y = (int) ev.getY();
//                int dy = y - lastY;
//                if (point[1] > -349) {
//                    Log.i("TAG","拦截"+point[1]);
//                    return true;
//                }else if(dy>0&&point[1] == -349){
//                    Log.i("TAG","拦截"+point[1]);
//                    return true;
//                }else if(dy<0&&point[1] == -349){
//                    Log.i("TAG","不拦截"+point[1]);
//                    return false;
//                }
                break;
            case MotionEvent.ACTION_DOWN:
                Log.i("TAG","ACTION_DOWN");
                break;
        }
        lastY = (int) ev.getY();
        return false;
//        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        boolean b = super.dispatchTouchEvent(ev);
        return b;
    }
}
